package retu;

import leave.LeaveStudent;
import leave.StudentList;

import java.util.Scanner;

public class LeaveOperation implements IOperation{

    @Override
    public void work(StudentList studentList) {
        System.out.print("请输入你的姓名:>");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int size = studentList.getUseSize();
        boolean flag = false;
        for (int i = 0; i < size; i++) {
            LeaveStudent leaveStudent = studentList.getLeaveStudents(i);
            if (name.equals(leaveStudent.getName())) {
                if ( flag == leaveStudent.isLeave() ) {
                    System.out.println("你已返校!");
                    return;
                } else {
                    leaveStudent.setLeave(true);
                    System.out.println("同意离校");
                    return;
                }
            }
        }
        System.out.println("输入错误,没有此学生!");
    }
}
